<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加客服</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/layui/css/layui.css" media="all">
</head>
<body style="padding: 0 10px;">

<blockquote class="layui-elem-quote layui-text" style="margin-top: 10px;">添加客服</blockquote>

<form class="layui-form" action="/index.php/staff/Staff_Manage/addStaff" method="post">
    {:token()}
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">客服名称</label>
            <div class="layui-input-inline">
                <input type="tel" name="name" placeholder="请输入客服名" lay-verify="required" autocomplete="off"
                       class="layui-input">
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label">客服状态</label>
            <div class="layui-input-block">
                <input type="checkbox" name="open" value="1" lay-skin="switch" lay-text="启用|禁用" checked>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-inline">
                <input type="tel" name="user_name" id="user_name" placeholder="请输入登录用户名" lay-verify="required"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-inline">
                <input type="text" name="password" placeholder="请输入密码" lay-verify="required"
                       class="layui-input">
            </div>
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">性别</label>
        <div class="layui-input-block">
            <input type="radio" name="sex" value="1" title="男">
            <input type="radio" name="sex" value="2" title="女">
            <input type="radio" name="sex" value="0" title="保密" checked>
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">描述</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入内容" name="description" class="layui-textarea"></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <a href="/index.php/staff/Staff_Manage/index" class="layui-btn">返回</a>
            <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script src="/static/layui/layui.js" charset="utf-8"></script>
<script>

    var user_name = [true, '用户名已被注册，请更换'];

    layui.use(['form', 'layer'], function () {
        var layer = layui.layer;
        var $ = layui.$;
        var form = layui.form;

        $(function () {
            $('#user_name').blur(function () {
                $.ajax({
                    url: '/index.php/staff/Register/ckUserName/user_name/' + $(this).val(),
                    dataType: 'json',
                    success: function (data) {
                        if (!data.no_exist) {
                            layer.tips(user_name[1], '#user_name');
                            // layer.msg('用户名已被注册，请更换');
                            user_name[0] = false;
                        } else {
                            user_name[0] = true;
                        }
                    }
                });
            });
        });

        form.on('submit(demo1)', function () {
            if (!user_name[0]) {
                layer.tips(user_name[1], '#user_name');
                return false;
            }
        });

    });
</script>
</body>
</html>